﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Media;

namespace GenTheme.Theme
{
    internal class MultiThread : IThread, IEnumerable<IThread>
    {
        private List<IThread> threads;
        private IThemeObject Owner;
        private IList<IThread> threadList = new List<IThread>();

        public MultiThread(IThemeObject owner)
        {
            this.Owner = owner;
        }

        #region IThread Members

        public IThemeObject ThemeObject
        {
            get
            {
                return this.Owner;
            }
        }

        public virtual int GetBotPath(IThread t)
        { 
            return 0;
        }
        public virtual int GetTopPath(IThread t)
        {
            return 0;
        }
        public virtual void SetColor(Color? c)
        { 
        }

        #endregion

        #region Explicit IThread Members

        IThread IThread.Top
        {
            get
            {
                return null;
            }
        }

        IThread IThread.Bot
        {
            get
            { 
                return null;
            }
        }

        Color? IThread.ThreadColor
        {
            get 
            {
                return new Color();
            }
        }

        bool IThread.IsVisible
        {
            get
            {
                return this.Owner.TopThread.Equals(this);
            }
            set
            {
                if (value != ((IThread)this).IsVisible)
                {
                    this.Owner.SwapThreads();
                }
            }
        }

        #endregion

        #region Explicit Multithread Members

        int IndexOf(IThread item)
        {
            IThread t = item as IThread;
            if (t != null)
            {
                return this.threadList.IndexOf(t);
            }
            return -1;
        }

        public IThread this[int index]
        {
            get
            {
                return this.threadList[index];
            }
        }

        public bool Contains(IThread item)
        {
            IThread t = item as IThread;
            if (t != null)
            {
                return this.threadList.Contains(t);
            }
            return false;
        }

        public int Count
        {
            get
            {
                return this.threadList.Count;
            }
        }

        #endregion

        #region IEnumerable<IThread> Members

        IEnumerator<IThread> IEnumerable<IThread>.GetEnumerator()
        {
            return (IEnumerator<IThread>)this.threadList.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.threadList.GetEnumerator();
        }

        #endregion
    }
}
